package com.bayihouse.model.vo;


import com.bayihouse.model.entity.Room;
import com.bayihouse.utils.MyDateUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import jnr.ffi.annotations.In;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

@AllArgsConstructor
@Data
@NoArgsConstructor
public class RoomVO implements Serializable {
    private static final long serialVersionUID = 3299535685581859835L;


    /**
     * 房子的ID
     */
    private Long id;


    /**
     * 房子的类型,是否用于租房
     */
    private Integer category;

    /**
     * 几楼
     */
    private Integer height;

    /**
     * 标签-有无地下室
     */
    private List<String> label;

    /**
     * 所属那一单元
     */
    private Long unitId;

    /**
     * 所属的小区
     */
    private Long communityId;


    /**
     * 创建时间
     */
    private String createTime;

    /**
     * 信息更新时间
     */
    private String updateTime;

    /**
     * 备注-房子的信息
     */
    private String detail;

    /**
     * 户主
     */
    private Long householdId;


    /**
     * 名称-比如203B,
     */
    private String name;


    private Long mannagerId;

    private String rentTime;

    private String district;

    private String street;

    private String address;

    public static RoomVO objToVO(Room room) {
        Gson gson = new Gson();
        RoomVO roomVO = new RoomVO();
        if (room == null) {
            return null;
        }
        if (room.getCategory() == null) {
            roomVO.setCategory(0);
        }
        roomVO.setRentTime(MyDateUtils.dateToString(room.getRentTime()));
        roomVO.setCreateTime(MyDateUtils.dateToString(room.getCreateTime()));
        roomVO.setLabel(gson.fromJson(room.getLabel(), List.class));
        BeanUtils.copyProperties(room, roomVO);
        return roomVO;
    }
}
